#!/bin/bash

#Copyright (c) 2025, Alibaba Cloud and its affiliates;
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at

#   http://www.apache.org/licenses/LICENSE-2.0

#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.


function printUsage() {
  echo "[usage]"
  echo "./deploy.sh [-p <install path>] [-e <python path>] [-u]"
  echo "-p specify server install path ; -e specify python env path"
}

node_name=$(curl -s -k http://100.100.100.200/latest/meta-data/hostname)

while getopts "p:e:" arg
do
  case $arg in
    p)
      HOME_PATH=$OPTARG
      ;;
    e)
      PYTHON_PATH=$OPTARG
      ;;
    ?)
      printUsage
      exit 1
      ;;
  esac
done

if [ "${HOME_PATH}" == '' ]
then
  HOME_PATH='/usr/local/fce/fce-server'
fi

if [ "${PYTHON_PATH}" == '' ]
then
  PYTHON_PATH='/usr/local/fce/python-3.11.9env/bin'
fi
# source /usr/local/fce/python3.9env/bin/activate

#cd $HOME_PATH
echo 'begin to start fce-server'
bash start.sh ${PYTHON_PATH}

echo 'begin to restart service'
systemctl restart fce-server.service

